<?php
/**
 * Pages_AdminController
 * 
 * @author
 * @version 
 */
class Call_IndexController extends Zend_Controller_Action {
	
public function init() {
		$this->model = new Call_Model_Item ();
		
		$form= new Call_Form_Contact();
		$form->setAction('/call/index/save');
		$this->form=$form;
	}
	
	
	
	public function indexAction() {
		if ($this->_request->isXmlHttpRequest ()) {
				$this->_helper->layout ()->disableLayout ();
		}
		$this->view->form =$this->form;
	}
	
	public function saveAction() {
		if ($this->_request->isXmlHttpRequest ()) {
			$res = array ();
			$params = $this->_getAllParams ();
			if (! $this->form->isValid ( $params )) {
				$errors = $this->form->getMessages ();
				$res ['errors'] = $errors;
				$res ['success'] = false;
				$this->_helper->json($res);
			} else {
				$params = $this->form->getValues ();
				$id = $this->model->create ( $params );
				$record = $this->model->select()->getOne ( 'id=' . $id );
				if ($record != false) {
					$res ['success'] = true;
					$res ['message'] = 'Спасибо, Ваше сообщение отправлено';
				} else {
					$res ['success'] = false;
				}
				$this->_helper->json($res);
			}
		}
	}
	

}
